﻿using SaaS.Core;
using System;
using System.Collections.Generic;
using System.Text;
using XCore.Extensions;
using XCore.Helper;
using XCore.Logger;
using XCore.Dependency;

namespace Web.Blog.Utils
{
    public class BlogLogger : LoggerBase
    {
        public BlogLogger() : base(CoreSetting.LogConnectionString, "BlogLogs")
        {
        }

        public void Log(string message)
        {
            throw new NotImplementedException();
        }

        public void Print(LoggerLevel level, string message, int code = 200, Exception exception = null)
        {
            LoggerInfo ei = new LoggerInfo();
            ei.Message = message;
            ei.Level = level;
            ei.Properties["Code"] = code;
            ei.Properties["Exception"] = exception;
            ei.Properties["ExecutionDuration"] = StopwatchHelper.Milliseconds;
            ei.Properties["CreationIpAddress"] = HttpContext.GetIp();
            ei.Properties["SystemType"] = (byte)HttpContext.GetOperatingType();
            ei.Properties["BrowserInfo"] = HttpContext.UserAgent();
            ei.Properties["CustomData"] = level == LoggerLevel.Trace ? null : HttpContext.GetRequestInfo();
            ei.Properties["CreationTime"] = DateTime.Now;
            this.DbLog(ei);
        }
    }
}
